var faces = [{
    "name": "[表情1]",
    "resource": "1.gif"
}, {
    "name": "[表情2]",
    "resource": "2.gif"
}, {
    "name": "[表情3]",
    "resource": "3.gif"
}, {
    "name": "[表情4]",
    "resource": "4.gif"
}, {
    "name": "[表情5]",
    "resource": "5.gif"
}, {
    "name": "[表情6]",
    "resource": "6.gif"
}, {
    "name": "[表情7]",
    "resource": "7.gif"
}, {
    "name": "[表情8]",
    "resource": "8.gif"
}, {
    "name": "[表情9]",
    "resource": "9.gif"
}, {
    "name": "[表情10]",
    "resource": "10.gif"
}, {
    "name": "[表情11]",
    "resource": "11.gif"
}, {
    "name": "[表情12]",
    "resource": "12.gif"
}, {
    "name": "[表情13]",
    "resource": "13.gif"
}, {
    "name": "[表情14]",
    "resource": "14.gif"
}, {
    "name": "[表情15]",
    "resource": "15.gif"
}, {
    "name": "[表情16]",
    "resource": "16.gif"
}, {
    "name": "[表情17]",
    "resource": "17.gif"
}, {
    "name": "[表情18]",
    "resource": "18.gif"
}, {
    "name": "[表情19]",
    "resource": "19.gif"
}, {
    "name": "[表情20]",
    "resource": "20.gif"
}, {
    "name": "[表情21]",
    "resource": "21.gif"
}, {
    "name": "[表情22]",
    "resource": "22.gif"
}, {
    "name": "[表情23]",
    "resource": "23.gif"
}, {
    "name": "[表情24]",
    "resource": "24.gif"
}, {
    "name": "[表情25]",
    "resource": "25.gif"
}, {
    "name": "[表情26]",
    "resource": "26.gif"
}, {
    "name": "[表情27]",
    "resource": "27.gif"
}, {
    "name": "[表情28]",
    "resource": "28.gif"
}, {
    "name": "[表情29]",
    "resource": "29.gif"
}, {
    "name": "[表情30]",
    "resource": "30.gif"
}, {
    "name": "[表情31]",
    "resource": "31.gif"
}, {
    "name": "[表情32]",
    "resource": "32.gif"
}, {
    "name": "[表情33]",
    "resource": "33.gif"
}, {
    "name": "[表情34]",
    "resource": "34.gif"
}, {
    "name": "[表情35]",
    "resource": "35.gif"
}, {
    "name": "[表情36]",
    "resource": "36.gif"
}, {
    "name": "[表情37]",
    "resource": "37.gif"
}, {
    "name": "[表情38]",
    "resource": "38.gif"
}, {
    "name": "[表情39]",
    "resource": "39.gif"
}, {
    "name": "[表情40]",
    "resource": "40.gif"
}, {
    "name": "[表情41]",
    "resource": "41.gif"
}, {
    "name": "[表情42]",
    "resource": "42.gif"
}, {
    "name": "[表情43]",
    "resource": "43.gif"
}, {
    "name": "[表情44]",
    "resource": "44.gif"
}, {
    "name": "[表情45]",
    "resource": "45.gif"
}, {
    "name": "[表情46]",
    "resource": "46.gif"
}, {
    "name": "[表情47]",
    "resource": "47.gif"
}, {
    "name": "[表情48]",
    "resource": "48.gif"
}, {
    "name": "[表情49]",
    "resource": "49.gif"
}, {
    "name": "[表情50]",
    "resource": "50.gif"
}, {
    "name": "[表情51]",
    "resource": "51.gif"
}, {
    "name": "[表情52]",
    "resource": "52.gif"
}, {
    "name": "[表情53]",
    "resource": "53.gif"
}, {
    "name": "[表情54]",
    "resource": "54.gif"
}, {
    "name": "[表情55]",
    "resource": "55.gif"
}, {
    "name": "[表情56]",
    "resource": "56.gif"
}, {
    "name": "[表情57]",
    "resource": "57.gif"
}, {
    "name": "[表情58]",
    "resource": "58.gif"
}, {
    "name": "[表情59]",
    "resource": "59.gif"
}, {
    "name": "[表情60]",
    "resource": "60.gif"
}, {
    "name": "[表情61]",
    "resource": "61.gif"
}, {
    "name": "[表情62]",
    "resource": "62.gif"
}, {
    "name": "[表情63]",
    "resource": "63.gif"
}, {
    "name": "[表情64]",
    "resource": "64.gif"
}, {
    "name": "[表情65]",
    "resource": "65.gif"
}, {
    "name": "[表情66]",
    "resource": "66.gif"
}, {
    "name": "[表情67]",
    "resource": "67.gif"
}, {
    "name": "[表情68]",
    "resource": "68.gif"
}, {
    "name": "[表情69]",
    "resource": "69.gif"
}, {
    "name": "[表情70]",
    "resource": "70.gif"
}, {
    "name": "[表情71]",
    "resource": "71.gif"
}, {
    "name": "[表情72]",
    "resource": "72.gif"
}, {
    "name": "[表情73]",
    "resource": "73.gif"
}, {
    "name": "[表情74]",
    "resource": "74.gif"
}, {
    "name": "[表情75]",
    "resource": "75.gif"
}, {
    "name": "[表情76]",
    "resource": "76.gif"
}, {
    "name": "[表情77]",
    "resource": "77.gif"
}, {
    "name": "[表情78]",
    "resource": "78.gif"
}, {
    "name": "[表情79]",
    "resource": "79.gif"
}, {
    "name": "[表情80]",
    "resource": "80.gif"
}, {
    "name": "[表情81]",
    "resource": "81.gif"
}, {
    "name": "[表情82]",
    "resource": "82.gif"
}, {
    "name": "[表情83]",
    "resource": "83.gif"
}, {
    "name": "[表情84]",
    "resource": "84.gif"
}, {
    "name": "[表情85]",
    "resource": "85.gif"
}, {
    "name": "[表情86]",
    "resource": "86.gif"
}, {
    "name": "[表情87]",
    "resource": "87.gif"
}, {
    "name": "[表情88]",
    "resource": "88.gif"
}, {
    "name": "[表情88]",
    "resource": "88.gif"
}];

var facesUtils = (function () {
    // 转化[xx]文字为图片
    var REGEX_RULE = /\[([^\]]+)\]/g;

    function convertToResource(text) {
        return text.replace(REGEX_RULE, function (res, val, index) {
            var targetResource = faces.filter(function (v) {
                return v.name === '[' + val + ']';
            });
            if (targetResource.length === 0) {
                return;
            }
            var targetResourceName = targetResource[0].name.replace('[', '').replace(']', '');
            return "<img class='face-image-content' src='static/dist/face/" + targetResource[0].resource + "' alt='" + targetResourceName + "'>";
        });
    }

    return {
        convertToResource: convertToResource,
    }
})();